package sys
{
	import flash.display.Sprite;
	/**
	 *代理人，app的入口 
	 * @author 张进辉
	 * 
	 */
	public class Fcade
	{
	
		private static var _appOpen:Boolean;
		public static function get open():Boolean
		{
			return _appOpen;
		}
		
		private static var _instance:Fcade;
		/**
		 *代理人实例 
		 * @return 
		 * 
		 */		
		public static function get instance():Fcade
		{
			if(_instance == null)
				_instance = new Fcade();
			
			return _instance;
		}
		
		
		//核心组件
		private var _cf:CoreObject;
		private var _ce:CoreEvent;
		
		public function Fcade()
		{
			if(_instance != null)
				throw new Error("通过Fcade.instance方法获得代理人实例");
		}
		
		public function singletonClass(cls:Class):*
		{
			return _cf.createClass(cls,CoreObject.SINGLETON);
		}
		
		public function reuseClass(cls:Class):*
		{
			return _cf.createClass(cls,CoreObject.REUSE);
		}
		
		/**
		 *事件处理类 
		 * @return 
		 * 
		 */		
		public function get coreEvent():CoreEvent
		{
			return _ce;
		}
		
		/**
		 *在执行其他方法前必须先执行该方法 
		 * @param app
		 * 
		 */		
		public function start(app:Sprite):void
		{
			if(!app) throw new Error("程序初始化失败");
			
			//不允许在其他地方实例化以下类
			_appOpen = true;
			
			_cf = new CoreObject(app);
			_ce = new CoreEvent(app);
			
			_appOpen = false;
		}
		
		
		public function set debug(value:Boolean):void
		{
			_cf.debug = value;	
			_ce.debug = value;
		}
		
	}
}